import pandas as pd
import jieba
from jieba import analyse
import numpy as np

df = pd.read_csv('../static/data/pre_job_info.csv')


def bar():
    job_list_string = ''.join(df['职位名称'].values.tolist())
    job_list_string = job_list_string.replace('/', '').replace(' ', '').replace('（', '').replace('）', '')
    df_job = pd.DataFrame(list(jieba.cut(job_list_string, cut_all=False))).rename(columns={0: 'word'})
    df_job_count = df_job.groupby('word').value_counts().reset_index().rename(columns={0: 'count'})
    df_job_count.to_csv('../static/data/bar_word.csv', index=None)


def word_cloud():
    keyword_list = [analyse.extract_tags(i, topK=10) for i in df['工作内容'].values.tolist()]
    keyword_list = np.array(keyword_list)
    keyword_list = keyword_list.ravel()
    df_keyword = pd.DataFrame(keyword_list).rename(columns={0: 'word'})
    df_keyword = df_keyword.groupby('word').value_counts().reset_index().rename(columns={0: 'count'})
    df_keyword.to_csv('../static/data/wordCloud_word.csv', index=None)


if __name__ == '__main__':
    bar()
    word_cloud()
